package com.es.service.impl;

import com.es.entity.SysRole;
import com.es.entity.SysUser;
import com.es.mapper.SysRoleMapper;
import com.es.mapper.SysUserMapper;
import com.es.mybatis.util.MybatisUtils;
import com.es.service.SysRoleService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 描述:
 * MyBatis-
 *
 * @author Derek
 * 创建时间：2022-05-10 10:39
 */
public class SysRoleServiceImpl implements SysRoleService {
    @Override
    public boolean save(SysRole sysRole) {
        SqlSession session = MybatisUtils.getSqlSession(false);
        SysRoleMapper mapper = session.getMapper(SysRoleMapper.class);
        int i = mapper.insert(sysRole);
        session.commit();
        session.close();
        return i>0;
    }

    @Override
    public SysRole get(Integer id) {
        SqlSession session = MybatisUtils.getSqlSession();
        SysRoleMapper mapper = session.getMapper(SysRoleMapper.class);
        SysRole role = mapper.get(id);
        session.close();
        return role;
    }

    @Override
    public List<SysRole> list() {
        SqlSession session = MybatisUtils.getSqlSession();
        SysRoleMapper mapper = session.getMapper(SysRoleMapper.class);
        List<SysRole> roles = mapper.list();
        session.close();
        return roles;
    }
}
